<?php
/**
 * @author ran
 */
namespace common\helper;
use Yii;

class HashHelper
{
	/**
	 * 获取hash加密串
	 * @method getUploadHash
	 * @param  string $time
	 * @return {string}
	 */
	public static  function getUploadHash($time) {
	    
	    if(empty($time)) {
	        return null;
	    }
	    
        return hash_hmac('sha256', $time, Yii::$app->params['hashkey'], false);
	     
	}
	
	/**
	 * 验证数据
	 * @method validateDataUploadHash
	 * @param {string} $hash 加密hash串
	 * @param {string} $time 时间戳
	 * @return {boolean}
	 */
	public static  function validateDataUploadHash($hash, $time) {
	    
	    return Yii::$app->security->compareString($hash,self::getUploadHash($time));
	}
	
}

?>